package com.xuecheng.media.controller;

import com.xuecheng.api.content.MediaApi;
import com.xuecheng.api.content.model.CourseBaseDTO;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.api.media.dto.MediaDTO;
import com.xuecheng.api.media.dto.TeachplanlMediaDTO;
import com.xuecheng.api.media.qo.QueryMediaModel;
import com.xuecheng.api.media.vo.BindTeachplanMediaVO;
import com.xuecheng.api.media.vo.MediaAuidVo;
import com.xuecheng.api.media.vo.MediaVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 媒资信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
//@RequestMapping("media")
public class MediaController  implements MediaApi {

    @Autowired
    private MediaService  mediaService;

    //保存媒资参粗
    @PostMapping("media")
    public MediaDTO createMedia(@RequestBody MediaVO vo) {
        Long companyId = SecurityUtil.getCompanyId();
        MediaDTO dto = MediaConvert.INSTANCE.vo2dto(vo);
        dto.setCompanyId(companyId);
        MediaDTO result = mediaService.createMedia(dto);

        return result;
    }

    //分页查询
    @PostMapping("media/list")
    public PageVO queryCourseList(PageRequestParams params, @RequestBody QueryMediaModel model) {
        Long aLong = SecurityUtil.getCompanyId();
        PageVO courseBases = mediaService.queryCourseList(params, model, aLong);
        return courseBases;
    }

    //预览视频
    @GetMapping("media/preview/{mediaId}")
    public String previewMedia(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();

        String vodUrl = mediaService.previewMedia(mediaId,companyId);

        return vodUrl;
    }

    //删除媒资
    @DeleteMapping("media/{mediaId}")
    public void removeMediaById(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        mediaService.removeMediaById(mediaId,companyId);
    }

    //分页查询媒资信息 运营
    @PostMapping("m/media/list")
    public PageVO queryMediaMList(PageRequestParams params,@RequestBody QueryMediaModel model) {

        return  mediaService.queryMediaMList(params,model);
    }



    //审核媒资信息 运营
    @PutMapping("m/media/audit")
    public void approveMedia(@RequestBody MediaAuidVo auditVO) {
        MediaDTO dto = MediaConvert.INSTANCE.votwo2dto(auditVO);
        mediaService.approveMedia(dto);

    }


    @GetMapping("m/media/preview{mediaId}")
    public String previewMediaOperation(Long mediaId) {
        String operation = mediaService.previewMediaOperation(mediaId);
        return operation;
    }




    @GetMapping("l/media/{mediaId}")
    public RestResponse<MediaDTO> getMediaById(@PathVariable Long mediaId) {

        RestResponse<MediaDTO> response = mediaService.getById4Service(mediaId);

        return response;
    }




}
